Skip to content

Fix/date invalid input 107#275

Open
SaumyaT-21 wants to merge 2 commits into
utksh1:mainfrom
SaumyaT-21:fix/date-invalid-input-107
Open

Fix/date invalid input 107#275
SaumyaT-21 wants to merge 2 commits into
utksh1:mainfrom
SaumyaT-21:fix/date-invalid-input-107

Conversation

@SaumyaT-21
Copy link
Copy Markdown

Description

This PR hardens the date parsing logic in src/utils/date.ts to prevent "Invalid Date" errors and unrealistic date overflows (e.g., year 99,999).

The parseDateSafe function was updated to include a semantic validation layer. While JavaScript's Date constructor can technically parse extreme numeric strings or overflow invalid months into the following year, this fix ensures that only dates within a realistic range (1900–2100) are treated as valid. If a date falls outside this range or is syntactically incorrect, the function now correctly returns null, allowing the UI to display a consistent 'N/A' fallback.

Related Issues

Closes #107

Type of Change

  • [ x ] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Performed unit testing using Vitest to verify the fix against multiple edge cases -

  1. Gibberish Strings: Verified that random text returns 'N/A'.
  2. Impossible Dates: Verified that overflow dates like "2026-13-45" are rejected.
  3. Extreme Years: Verified that large numeric strings (e.g., "99999") are caught by the new range check.

Result: All 91 tests passed successfully

Checklist

  • [ x ] My code follows the code style of this project.
  • [ x ] I have performed a self-review of my own code.
  • [ x ] I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • [ x ] My changes generate no new warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] Add unit tests for date formatting invalid-input behavior

1 participant